package com.mazaiting.classfile.attr.info;

import com.mazaiting.classfile.ClassReader;
import com.mazaiting.classfile.constant.ConstantPool;
import lombok.Getter;

/**
 * 签名
 * 定长属性
 *
 * @author mazaiting
 * @since 2021/8/12
 */
@Getter
public class SignatureAttribute extends AttributeInfo {
    /**
     * 常量索引 无符号 u2
     */
    private int signatureIndex;

    public SignatureAttribute(ConstantPool pool, int index, int length) {
        super(pool, index, length);
    }

    @Override
    public void readInfo(ClassReader reader) {
        this.signatureIndex = reader.readU2ToUnsignedShort();
    }

    /**
     * 获取签名
     * @return 签名
     */
    public String getSignature() {
        return pool.getUtf8(signatureIndex);
    }

    @Override
    public String toString() {
        return "ConstantSignatureAttribute{" +
                "signatureIndex=" + signatureIndex +
                '}';
    }
}


















